﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
using WPFExcelReport.Helpers;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Windows.Input;
namespace WPFExcelReport
{
    public partial class THMGB02
    {
        public THMGB02()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VGLLG();
            this.DataContext = MV;
            InitializeComponent();
        }

        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);//

            if (dwMaster == null)
            {
                KEY = "";

            }
            else
            {
                KEY = TMV.GLLBEHI + TMV.GLLO + TMV.GLLB + "LIKE '" + TMV.GLLP.Trim() + "%'";
            }
        }

        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            base.QueryCommand(sender, e);
            dwData = TBMain.NewRow();
            dwData["GLMANDANT"] = app.Mandant;
            dwData["GLLO"] = LO;
            dwData["GLLB"] = LB;
            dwData["GLLP"] = "LIKE '"+LP.Trim()+"%'";
            dwData["GLBEM"] = " LIKE '"+ART.Trim()+"%'";
            dwData["GLLBEH"] = " LIKE '"+FARBE.Trim()+"%'";
            dwData["GLLBEHI"] = " LIKE '"+TKEY1.Trim()+"%'";
            dwData["GLFILLER1"] = "LIKE '"+TKEY2.Trim()+"%'";
            dwData["GLAUFMSL"] = "LIKE '" + TKEY3.Trim() + "%'";
            SResult = TMV.QGLLG11(dwData);
            if (SResult.Tables.Count > 0)
            {
                string typ = "";
                foreach (DataRow dw in SResult.Tables[0].Rows)
                {
                    typ = dw["AB"].ToString();

                    if (typ == "" ||typ==null)
                    {                      
                        dw["CD"] = dw["GLBSTKG"];
                    }


                }

            }
            MergeData(SResult, true);

        }

        public void QUERY_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                this.Focus();
                QueryCommand(null, null);
            }

        }

    }
}
